package com.example.module_web.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.module_web.R;
import com.example.module_web.beans.Product;

import java.util.HashMap;
import java.util.List;

/**
 * Created by ASUS on 2018/3/15.
 */

public class ProductAdapter extends FormAdapter<Product> {

    public ProductAdapter(Context context, List<Product> items) {
        super(context, items);
    }

    @Override
    public HashMap<String, View> onBindItemViewId(HashMap<String, View> holder, View itemView) {
        holder.put(NUM,itemView.findViewById(R.id.item_form_num));
        holder.put(PRODUCT,itemView.findViewById(R.id.item_form_product));
        holder.put(SALEPRICE,itemView.findViewById(R.id.item_form_saleprice));
        holder.put(INVENTORY,itemView.findViewById(R.id.item_form_invertory));
        holder.put(RETAILPRICE,itemView.findViewById(R.id.item_form_retailprice));
        holder.put(SPECIFICATION,itemView.findViewById(R.id.item_form_specification));
        holder.put(ACTIVE,itemView.findViewById(R.id.item_form_active));
        return holder;
    }

    @Override
    protected int setItemLayoutId() {
        return R.layout.web_item_frag20_product;
    }

    @Override
    protected void onBindFormData(HashMap<String, View> holder, Object o) {
        Product product = (Product) o;
        ((TextView)holder.get(NUM)).setText(String.format("%s)", String.valueOf(product.getNumber())));
        ((TextView)holder.get(PRODUCT)).setText(product.getProduct());
        ((TextView)holder.get(SALEPRICE)).setText(String.valueOf(product.getSalePrice()));
        ((TextView)holder.get(INVENTORY)).setText(String.valueOf(product.getInventory()));
        ((TextView)holder.get(RETAILPRICE)).setText(String.valueOf(product.getRetailPrice()));
        ((TextView)holder.get(SPECIFICATION)).setText(product.getSpecification());
        ((TextView)holder.get(ACTIVE)).setText(product.getActivite());
    }
}
